#include <bits/stdc++.h>

using namespace std;

int a[2222],b[2222],c[2222],la,lb,lc;
int main()
{
    int n;
    string q,w;
    cin>>n>>q>>w;
    la = q.length();
    lb = w.length();
    for(int i=1;i<=la;i++){
        if(q[la-i]>='A'&&q[la-i]<='Z'){
            a[i] = q[la-i] - 'A' +10;
        }
        else a[i] = q[la-i]-'0';
    }
    for(int i=1;i<=lb;i++){
        if(w[lb-i]>='A'&&w[lb-i]<='Z'){
            b[i] = w[lb-i] - 'A' +10;
        }
        else b[i] = w[lb-i]-'0';
    }
    lc = max(la,lb);
    for(int i=1;i<=lc;i++){
        c[i] += a[i] + b[i];
        c[i+1] += c[i]/n;
        c[i] = c[i]%n;
    }
    if(c[lc+1]>0)lc++;
    for(int i=lc;i>=1;i--){
        if(c[i]>=10)cout<<(char)('A'+c[i]-10);
        else cout<<c[i];
    }
    return 0;
}
